package com.zu.commu.dataSource.imp;

import com.zu.commu.dataSource.NcsConnection;
import com.zu.commu.dataSource.NcsDataSource;
import com.zu.commu.dataSource.imp.pool.NcsDataSourceManager;

import java.sql.Connection;

public class NcsDataSourceImp
  implements NcsDataSource
{
  private NcsDataSourceManager ncsDataSourceManager;
  private String connectPoolName;

  public void createDataSource(NcsDataSourceManager ncsDataSourceManager, String connectPoolName)
  {
    this.connectPoolName = connectPoolName;
    this.ncsDataSourceManager = ncsDataSourceManager;
  }

  public NcsConnection getNcsConnetion(long time)
  {
    Connection c = this.ncsDataSourceManager.getConnection(this.connectPoolName, time);
    if (c == null) {
      return null;
    }
    NcsConnectionImp cimp = new NcsConnectionImp(this.ncsDataSourceManager, 
      this.connectPoolName, 
      c);
    return cimp;
  }

  public void destroyDataSource()
  {
    this.ncsDataSourceManager.release();
  }
}